package com.yunfei.springbootgoods.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yunfei.springbootgoods.dto.Page;
import com.yunfei.springbootgoods.entity.Goods;
import com.yunfei.springbootgoods.entity.GoodsOrder;
import com.yunfei.springbootgoods.mapper.GoodsMapper;
import com.yunfei.springbootgoods.mapper.GoodsOrderMapper;
import com.yunfei.springbootgoods.service.GoodsOrderService;
import com.yunfei.springbootgoods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class GoodsOrderServiceImpl implements GoodsOrderService {

    @Autowired
    private GoodsOrderMapper goodsOrderMapper;

    @Override
    public void addGoodsOrder(Integer goodsId) {
        GoodsOrder goodsOrder = new GoodsOrder();
        goodsOrder.setGoodsId(goodsId);
        goodsOrder.setOrderTime(new Date());
        goodsOrderMapper.addGoodsOrder(goodsOrder);

    }

    @Override
    public void updateGoodsOrder01(Integer orderId) {
        goodsOrderMapper.updateGoodsOrder01(orderId);
    }

    @Override
    public void updateGoodsOrder02(Integer orderId) {
        goodsOrderMapper.updateGoodsOrder02(orderId);
    }

    @Override
    public Page getGoodsOrderPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();

        PageHelper.startPage(pageNo,pageSize);
        List<GoodsOrder> goodsOrderList = goodsOrderMapper.getGoodsOrderList();
        PageInfo<GoodsOrder> info = new PageInfo<>(goodsOrderList);

        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setCount((int) info.getTotal());
        page.setPageCount(info.getPages());
        page.setData(info.getList());
        return page;
    }
}
